<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>bootstrap-treeview测试</title>
	<link rel="stylesheet" href="../../../static/lib/plugins/bootstrap/css/bootstrap.css">
	<link rel="stylesheet" href="../../../static/lib/plugins/bootstrap-treeview/bootstrap-treeview.css">
	<script type="text/javascript" src="../../../static/lib/plugins/jQuery/jquery-2.2.3.min.js"></script>
	<script type="text/javascript" src="../../../static/lib/plugins/bootstrap-treeview/bootstrap-treeview.js"></script>
</head>
<body>
	<div id="tree" style="width: 400px;height: 1000px;margin-left: auto;margin-right: auto;"></div>
    <div id="testDate"></div>
	<script type="text/javascript">
		//获取树形结构列表数据
            function getTree() {
                var tree = [{
                    text: "Parent 1",
                    nodes: [{
                        text: "Child 1",
                        nodes: [{
                            text: "Grandchild 1"
                        }, {
                            text: "Grandchild 2"
                        }]
                    }, {
                        text: "Child 2"
                    }]
                }, {
                    text: "Parent 2"
                }, {
                    text: "Parent 3"
                }, {
                    text: "Parent 4"
                }, {
                    text: "Parent 5"
                }];
                return tree;
            }
            
            //初始化树形结构列表
            $('#tree').treeview({
                data: getTree()
            });
            
            //最后一次触发节点Id
            var lastSelectedNodeId = null;
            //最后一次触发时间
            var lastSelectTime = null;
            
            //自定义业务方法
            function customBusiness(data){
                alert("双击获得节点名字： "+data.text);
            }

            function clickNode(event, data) {
                if (lastSelectedNodeId && lastSelectTime) {
                    var time = new Date().getTime();
                    var t = time - lastSelectTime;
                    if (lastSelectedNodeId == data.nodeId && t < 300) {
                        customBusiness(data);
                    }
                }
                lastSelectedNodeId = data.nodeId;
                lastSelectTime = new Date().getTime();
            }
            
            //自定义双击事件
            function customDblClickFun(){
                //节点选中时触发
                $('#tree').on('nodeSelected', function(event, data) {
                    clickNode(event, data)
                });
                //节点取消选中时触发
                $('#tree').on('nodeUnselected', function(event, data) {
                    clickNode(event, data)
                });
            }
            $(function() {
            	customDblClickFun();
            });	
	</script>
</body>
</html>